// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//
#pragma once

#include <optional>

#if __has_include("filesystem")
#include <filesystem>
namespace fs = std::filesystem;
#else
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#endif

namespace kumo::pollux::common {
    /// Generates a file directory on local file system specified by 'dirPath'. The
    /// generation will be recursive. Non-exist parent directories will also be
    /// created. Returns true if creation is successful, false otherwise. Error
    /// message will be printed if creation is unsuccessful, but the created
    /// directories will not be removed on failure.
    bool generateFileDirectory(const char *dirPath);

    /// Creates a file with a generated file name in provided 'basePath'. The
    /// generated file will have random chars in the file name to avoid duplication.
    /// The full path of the file will be of the pattern
    /// {basePath}/pollux_{prefix}_XXXXXX where 'XXXXXX' is the randomly generated
    /// chars. A nullopt will be returned if file creation fails.
    std::optional<std::string> generateTempFilePath(
        const char *basePath,
        const char *prefix);

    /// Creates a directory with a generated directory name in provided 'basePath'.
    /// The generated directory will have random chars in it to avoid duplication.
    /// The full path of the directory will be of the pattern
    /// {basePath}/pollux_{prefix}_XXXXXX where 'XXXXXX' is the randomly generated
    /// chars. A nullopt will be returned if directory creation fails.
    std::optional<std::string> generateTempFolderPath(
        const char *basePath,
        const char *prefix);
} // namespace kumo::pollux::common
